package com.hjq.www.View;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Create with IntelliJ IDEA
 *
 * @author: hjq
 * @Date:
 * @Description:
 */
public class MainView extends JFrame {
    /**
     * 创建菜单条
     */
    JMenuBar menu = new JMenuBar();
    /**
     * 创建菜单组件
     */
    JMenu userMenu = new JMenu("用户模块");
    JMenu visitorMenu = new JMenu("参观者模块");
    JMenu breederMenu = new JMenu("饲养员模块");
    JMenu masterMenu = new JMenu("园长模块");
    JMenu setupMenu = new JMenu("设置");
    /**
     * 菜单项组件
     */
    JMenuItem information = new JMenuItem("信息管理");
    JMenuItem ticket = new JMenuItem("门票服务");
    JMenuItem visit=new JMenuItem("参观园区");
    JMenuItem park = new JMenuItem("园区管理");
    JMenuItem animal = new JMenuItem("动物管理");
    JMenuItem breeders = new JMenuItem("饲养员管理");
    JMenuItem parks = new JMenuItem("园区管理");
    JMenuItem change = new JMenuItem("切换账号");
    JMenuItem exit = new JMenuItem("退出系统");
    TextArea ta = new TextArea(10, 100);

    /**
     * 组装视图
     */
    public void init() {
        JFrame jf = new JFrame("ws动物园,欢迎您");
        int Width = jf.getWidth();
        int Height = jf.getHeight();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int width = screenSize.width;
        int height = screenSize.height;
        jf.setLocation(width / 3 - Width, height / 4 - Height);
        breeders.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new BreederView().BreederMaster();
                dispose();
            }
        });
        information.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                RegisterView r=new RegisterView();
                r.UserView();
                dispose();
            }
        });
        change.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new LoginView();
                jf.dispose();
            }
        });
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        park.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ZoosMasterView();
            }
        });
        parks.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ZoosMasterView().showZoos();
                dispose();
            }
        });
        visit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ZoosMasterView();
                dispose();
            }
        });
        animal.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AnimalView().AnimalMaster();
            }
        });
        //组建用户模块菜单
        userMenu.add(information);
        //组建参观者模块菜单
        visitorMenu.add(ticket);
        visitorMenu.add(visit);
        //组建饲养员模块
        breederMenu.add(park);
        breederMenu.add(animal);
        //组建园长模块
        masterMenu.add(parks);
        masterMenu.add(breeders);
        //组建设置模块
        setupMenu.add(change);
        setupMenu.add(exit);
        //组装菜单条
        menu.add(userMenu);
        menu.add(visitorMenu);
        menu.add(breederMenu);
        menu.add(masterMenu);
        menu.add(setupMenu);
        jf.setJMenuBar(menu);
        jf.add(ta);
        //设置界面最佳大小并可见
        jf.pack();
        jf.setVisible(true);
    }
}

